package com.woniuxy.coachweb.controller;


import com.woniuxy.coachdao.model.JoinVenue;
import com.woniuxy.coachmodel.dto.JoinVenueDto;
import com.woniuxy.coachmodel.form.CoachDisposeForm;
import com.woniuxy.coachservice.exception.CoachException;
import com.woniuxy.coachservice.service.JoinVenueService;
import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.MyJwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 入驻商家表 前端控制器
 * </p>
 *
 * @author 冉杰
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/joinVenue")
@Api(tags = "教练-场馆互邀服务信息接口")
public class JoinVenueController {
    @Autowired
    private JoinVenueService joinVenueService;

    @GetMapping("/joinVenue.coach")
    @ApiOperation("教练申请入驻场馆接口")
    public Result joinVenue(Integer venueId,String message,@RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        joinVenueService.joinVenue(venueId,coachId,message);
        return Result.success("教练成功申请入住场馆");
    }


    @GetMapping("/inviteCoach.venue")
    @ApiOperation("场馆邀请教练入驻接口")
    public Result inviteCoach(Integer coachId,String message,@RequestHeader String token){
        Integer venueId = MyJwtUtil.getVenueIdByKey(token, "venueId");
        joinVenueService.inviteCoach(venueId,coachId,message);
        return Result.success("场馆成功邀请教练入住场馆");
    }

    @GetMapping("/look")
    @ApiOperation("根据Id查询场馆入驻申请记录接口")
    public Result look(Integer joinId){
        JoinVenue joinVenue = joinVenueService.look(joinId);
        return Result.success("根据Id查看入住场馆申请记录成功",joinVenue);
    }

    @GetMapping("/coachLook.coach")
    @ApiOperation("教练查看入驻申请接口")
    public Result coachLook(@RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        List<JoinVenueDto> dtos = joinVenueService.coachLook(coachId);
        return Result.success("教练查看入住场馆申请记录成功",dtos);
    }

    @GetMapping("/venueLook.venue")
    @ApiOperation("场馆查看入驻申请接口")
    public Result venueLook(@RequestHeader String token){
        Integer venueId = MyJwtUtil.getVenueIdByKey(token, "venueId");
        List<JoinVenueDto> dtos = joinVenueService.venueLook(venueId);
        return Result.success("场馆查看入住场馆申请记录成功",dtos);
    }

    @PostMapping("/coachAgree.coach")
    @ApiOperation("教练同意入驻场馆申请接口")
    public Result coachAgree(@RequestBody CoachDisposeForm form, @RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        joinVenueService.coachAgree(form,coachId);
        return Result.success("教练同意场馆申请记录成功");
    }
    @PostMapping("/coachRefuse.coach")
    @ApiOperation("教练拒绝入驻场馆申请接口")
    public Result coachRefuse(@RequestBody CoachDisposeForm form, @RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        joinVenueService.coachRefuse(form,coachId);
        return Result.success("教练拒绝场馆申请记录成功");
    }

    @PostMapping("/venueAgree.venue")
    @ApiOperation("场馆同意教练入驻申请接口")
    public Result venueAgree(@RequestBody CoachDisposeForm form, @RequestHeader String token){
        Integer venueId = MyJwtUtil.getVenueIdByKey(token, "venueId");
        joinVenueService.venueAgree(form,venueId);
        return Result.success("场馆同意教练入驻成功");
    }

    @PostMapping("/venueRefuse.venue")
    @ApiOperation("场馆拒绝教练入驻申请接口")
    public Result venueRefuse(@RequestBody CoachDisposeForm form, @RequestHeader String token){
        Integer venueId = MyJwtUtil.getVenueIdByKey(token, "venueId");
        joinVenueService.venueRefuse(form,venueId);
        return Result.success("场馆拒绝教练入驻成功");
    }

}

